package com.module.prms;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.log4j.Logger;

import base.util.ResolveUnit;

import com.activityClient.client.ActivityThread;
import com.module.prms.manager.RoleEntEventManager;
import com.module.prms.vo.PrmsRoleEntEvent;
import com.module.sys.ConstantUnit;
import com.webClient.client.SocketClient;
import com.webClient.service.WebClientService;

public class prmsRoleEntEventService {
	static SocketClient sClient = null;
	static WebClientService ss = null;
	static Logger logger = Logger.getLogger(prmsRoleService.class.getName ()) ;
	
	 private String getJson(Map map) throws Exception{
		String sessionId = UUID.randomUUID().toString();
 	    map.put(ConstantUnit.STATUS_NAME, ConstantUnit.STATUS_SEND);
 	    map.put(ConstantUnit.SESSIONID_NAME,sessionId );
 	    map.put(ConstantUnit.B_ID, "prms");
 	    map.put(ConstantUnit.CN, "PrmsRoleEntEvent");   
	    String json = ResolveUnit.getJsonStr(map);
	    return json;
	 }
	 
	 private PrmsBaseBean returnValue(Map map)throws Exception {
		 try {
			 	String sendmsg = getJson(map);
			 	logger.info("prms发送的报文是："+sendmsg);
		        ActivityThread tc = ActivityThread.getInstance();
				String receiveMessage = null;
				try {
					receiveMessage = tc.sendAndReceive(sendmsg, map.get("sid").toString());
					logger.info("prms接收的报文是："+receiveMessage);
					PrmsBaseBean beanUnit = ResolveUnit.resolve(receiveMessage, PrmsBaseBean.class);
					return beanUnit;
				} catch (Exception e) {
					throw e;
				}
				
		} catch (Exception e) {
			throw e;
		}
	 }
	 
	 /**
	  * 保存企业溯源流程操作权限
	  * @param roleEntEvent
	  * @return
	  * @throws Exception
	  */
	 public Map saveEntEvent(List flowlist,String roleid) {

			try {
				Map map = new HashMap();		 	    	    
				 RoleEntEventManager roleEntEventManager = RoleEntEventManager.getInstance();
				 map = roleEntEventManager.roleEntEventSave(flowlist, roleid);
				 return map;
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
	 }
	 /**
	  * 获取企业拥有的溯源流程
	  * @param roleid
	  * @return
	  */
	 public List listRoleEntEvent(String roleid){
	
		 try{

			 RoleEntEventManager roleEntEventManager = RoleEntEventManager.getInstance();
			 List list = roleEntEventManager.listRoleEntEvent(roleid);
	  	     return list;
		 }catch(Exception e){
			 e.printStackTrace();
			 return null;
		 }
	 }
	 /**
	  * 企业用户查询本企业的溯源流程权限列表
	  * @param orgid
	  * @return
	  */
	 public List listFlowEvent(String roleid){
		
		 try
		 {
			 RoleEntEventManager roleEntEventManager = RoleEntEventManager.getInstance();			 
			 List list = roleEntEventManager.listFlowEvent(roleid);
			 return list;
		 }catch(Exception e){
			 e.printStackTrace();
			 return null;
		 }
	 }
	 
	 
}
